// import _ from 'lodash'

// export function parseEnv(env) {
//   const envs = _.cloneDeep(env)

//   Object.entries(env).forEach(([key, value]) => {
//     if (value === 'true' || value === 'false') envs[key] = value === 'true'
//     else if (/^\d+$/.test(value)) envs[key] = Number(value)
//     else if (value === 'null') envs[key] = null
//     else if (value === 'undefined') envs[key] = undefined
//   })
//   return envs
// }

// Read all environment variable configuration files to process.env
export function wrapperEnv(envConf) {
  const ret = {}

  for (const envName of Object.keys(envConf)) {
    let realName = envConf[envName].replace(/\\n/g, '\n')
    realName = realName === 'true' ? true : realName === 'false' ? false : realName

    if (envName === 'VITE_PORT') {
      realName = Number(realName)
    }
    if (envName === 'VITE_PROXY') {
      try {
        realName = JSON.parse(realName)
      } catch (error) {
        realName = ''
      }
    }
    ret[envName] = realName
    if (typeof realName === 'string') {
      process.env[envName] = realName
    } else if (typeof realName === 'object') {
      process.env[envName] = JSON.stringify(realName)
    }
  }
  return ret
}
